package com.qumitech.visualnovel.service.userStatistics.impl;

import com.alibaba.fastjson.JSONObject;
import com.qumitech.visualnovel.component.exception.BusinessException;
import com.qumitech.visualnovel.component.util.HttpInvokeUtil;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.model.common.UrlConstant;
import com.qumitech.visualnovel.service.userStatistics.UserBehaviorStatisticsService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author: ywxie
 * @Date: 2019/7/18 11:17
 * @Description:
 */
@Service
public class UserBehaviorStatisticsServiceImpl implements UserBehaviorStatisticsService {

    private final String USER_BEHAVIOR_STATISTICES_URL = "/userbehaviorstatistics/console";
    private final String NUMBER_URL = "/num";

    @Override
    public Map<String, Object> getUserDataNum(Map<String, String> paramMap) {
        String url = UrlConstant.SERVER_URL + USER_BEHAVIOR_STATISTICES_URL + NUMBER_URL;
        String body = HttpInvokeUtil.httpGet(url, paramMap, null);
        BaseRsp rsp = JSONObject.parseObject(body, BaseRsp.class);
        if (rsp == null || rsp.getStatus() != ResultEnum.SUCCESS.getState()
                || rsp.getData() == null) {
            throw new BusinessException(ResultEnum.FAILURE);
        }
        Map<String, Object> rspMap = (Map<String, Object>) rsp.getData();
        return rspMap;
    }
}
